import { Controller, Get, Query, Request, UseGuards } from "@nestjs/common";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import {
  GetGoodsDetailsDto,
  GetGoodsDto,
  GetGoodsListDto,
  GetGoodsTypeDto,
} from "../dto/goods.dto";
import { WeappGoodsService } from "./goods.service";
import { RolesGuard } from "/@/logical/adminModule/auth/roles.guard";

@ApiTags("weapp-goods")
@Controller("goods")
@UseGuards(RolesGuard)
export class WeappGoodsController {
  constructor(private readonly goodsService: WeappGoodsService) {
    //
  }

  @Get("getGoodsTypeByPid")
  @ApiOperation({ summary: "获取商品分类" })
  async getGoodsTypeByPid(@Query() query: GetGoodsTypeDto): Promise<any> {
    return this.goodsService.getGoodsTypeByPid(query);
  }

  @Get("getGoodsList")
  @ApiOperation({
    summary: "获取商品列表，根据搜索字段 什么都不传则根据推荐指数",
  })
  async getGoodsList(@Query() query: GetGoodsListDto): Promise<any> {
    return this.goodsService.getGoodsList(query);
  }

  @Get("getGoodsListByType")
  @ApiOperation({ summary: "获取商品列表，根据商品类型" })
  async getGoodsListByType(@Query() query: GetGoodsDto): Promise<any> {
    return this.goodsService.getGoodsListByType(query);
  }

  @Get("getGoodsDetails")
  @ApiOperation({ summary: "获取商品详情" })
  async getGoodsDetails(
    @Query() query: GetGoodsDetailsDto,
    @Request() request,
  ): Promise<any> {
    return this.goodsService.getGoodsDetails(query, request.user);
  }
}
